package com.yedean.mall.portal.client;

import com.yedean.mall.portal.domain.WxMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class DefaultWxClient extends AbstractWxClient {
    private final WxProperties properties;

    public DefaultWxClient(RestTemplate restTemplate, WxProperties properties) {
        super(restTemplate);
        this.properties = properties;
    }


    @Override
    public WxMessage getMessage(String code) {
        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        params.add("appid", properties.getAppid());
        params.add("secret", properties.getSecret());
        params.add("js_code", code);
        params.add("grant_type", "authorization_code");
        String url = properties.getUrl();
        return post(url, params, WxMessage.class);
    }
}
